package com.hrms.controller;

import com.hrms.domain.Task;
import com.hrms.domain.web.TableDataInfo;
import com.hrms.domain.web.AjaxResult;
import com.hrms.service.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 目标管理Controller
 * 
 * @author 老詹
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/admin/task")
public class TaskController extends BaseController
{
    @Autowired
    private ITaskService taskService;

    /**
     * 查询目标任务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Task task)
    {
        startPage();
        task.setEmpNo(getEmpNoFromSession());
        List<Task> list = taskService.selectTaskList(task);
        return getDataTable(list);
    }


    /**
     * 获取目标任务详细信息
     */
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(taskService.selectTaskByTaskId(taskId));
    }

    /**
     * 新增目标任务
     */
    @PostMapping
    public AjaxResult add(@RequestBody Task task)
    {
        task.setEmpNo(getEmpNoFromSession());
        return toAjax(taskService.insertTask(task));
    }

    /**
     * 修改目标任务
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Task task)
    {
        return toAjax(taskService.updateTask(task));
    }

    /**
     * 删除目标任务
     */
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(taskService.deleteTaskByTaskIds(taskIds));
    }
}
